<?php
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
///关于标基本标的统计信息
$basewhere      = "";
if($startdate!="" && $enddate!=""){
  $basewhere    = " and reverify_time>='$startdate' and  reverify_time<='$enddate'";  
}

$rows = $dbselect->GetRows("SELECT cid, SUBSTR(reverify_time,1,10) as reverify_time, SUM( account ) AS v_acount, COUNT( account ) AS c_acount,
SUM( repay_account_interest ) AS v_account_i,sum(repay_account_other) AS v_account_o, SUM( account_diya ) AS v_account_d,
SUM( borrow_jiangli ) AS v_jiangli, sum( IF( borrow_jiangli >0, 1, 0 ) ) AS c_jiangli
FROM 05b_0base
WHERE STATUS IN ( 3, 6 )  $basewhere
GROUP BY cid, SUBSTR( reverify_time, 1, 10 ) "); // 每次处理 100 行
foreach($rows as &$row)
{   
    $cid    = $row['cid'];
    $ctime  = strtotime($row['reverify_time']);
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    $count  = $row['c_acount'];
    $c_jl   = $row['c_jiangli'];
    //标复审后
    if($row['v_acount']*1<>0){
        CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_st01",1,'tot_b_account',$row['v_acount'], $Y, $M, $D); //网站统计信息 借款总额
        CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_cid",$cid,"tot_b_account",$row['v_acount'],$Y, $M, $D);     //分站的借款总额 
    }
    
    if($row['v_account_i']*1<>0){
         CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_st01",1,'tot_b_interest',$row['v_account_i'], $Y, $M, $D); //该还利息总计
         CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_cid",$cid,"tot_b_interest",$row['v_account_i'],$Y, $M, $D); //该还利息
    }
   
    if($row['v_account_o']*1<>0){
        CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_st01",1,'tot_b_other',$row['v_account_o'], $Y, $M, $D);    //总计  其他费费
        CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_cid",$cid,"tot_b_other",$row['v_account_o'],$Y, $M, $D);    //总计  其他费费
    }
    
    if($row['v_account_d']*1<>0){
        CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_st01",1,'tot_b_yajin',$row['v_account_d'],$Y, $M, $D);     //押金=
        CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_cid",$cid,"tot_b_yajin",$row['v_account_d'],$Y, $M, $D);    //押金       
    }
    if($row['v_account_d']*1<>0){
        CTLog::G()->doctAndDayReal($c_jl.",rp_{$Y}{$m}_st01",1,'tot_b_jiangli',$row['v_jiangli'],$Y, $M, $D);     //网站统计 奖励金额                        
        CTLog::G()->doctAndDayReal($c_jl.",rp_{$Y}{$m}_cid",$cid,"tot_b_jiangli",$row['v_jiangli'],$Y, $M, $D);//分站统计 奖励金额
    }
}
